package com.xiaoxi.exam.service;

import cn.xinzhili.xutils.core.util.HashUtils;
import com.xiaoxi.exam.bean.enums.MessageType;
import com.xiaoxi.exam.dao.MessageMapper;
import com.xiaoxi.exam.model.Message;
import com.xiaoxi.exam.model.MessageExample;
import java.util.List;
import java.util.Objects;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class MessageService {

  @Autowired
  private MessageMapper messageMapper;


  public List<Message> getMessageByOpenId(String openId, MessageType type) {
    MessageExample example = new MessageExample();
    example.or().andOpenIdEqualTo(openId).andTypeEqualTo(type).andDeletedAtIsNull();
    return messageMapper.selectByExample(example);
  }

  public Message getMessageById(String id) {
    Message message = messageMapper.selectByPrimaryKey(HashUtils.decode(id));
    if (Objects.isNull(message.getDeletedAt())) {
      return message;
    } else {
      return null;
    }
  }
}
